import App from './App'
// 挂载请求
import tools from '@/helpYouShop/utils/tools';
import http from '@/helpYouShop/request';
Vue.prototype.$http = http;
Vue.prototype.$tools = tools;
Vue.prototype.serviceUrl = 'https://takeaway.bangniya.cn'

// Vue.prototype.serviceUrl = 'http://127.0.0.1:444'
Vue.prototype.getDateymd = function(shijianchuo) {
	//shijianchuo是整数，否则要parseInt转换
	var shijianchuo = parseInt(shijianchuo) * 1000;
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y + '-' + this.add0(m) + '-' + this.add0(d);
};
Vue.prototype.getDatehmm = function(shijianchuo) {
	//shijianchuo是整数，否则要parseInt转换
	var shijianchuo = parseInt(shijianchuo) * 1000;
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return this.add0(h) + ':' + this.add0(mm);
};
//乘法函数，用来得到精确的乘法结果

//说明：javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。

//调用：accMul(arg1,arg2)

//返回值：arg1乘以arg2的精确结果

Vue.prototype.accMul = function(arg1, arg2) {

	var m = 0,
		s1 = arg1.toString(),
		s2 = arg2.toString();

	try {
		m += s1.split(".")[1].length
	} catch (e) {}

	try {
		m += s2.split(".")[1].length
	} catch (e) {}

	return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)

}

Vue.prototype.accDiv = function(arg1, arg2) {
	var t1 = 0,
		t2 = 0,
		r1, r2;
	try {
		t1 = arg1.toString().split(".")[1].length
	} catch (e) {}
	try {
		t2 = arg2.toString().split(".")[1].length
	} catch (e) {}
	Math.r1 = Number(arg1.toString().replace(".", ""))
	Math.r2 = Number(arg2.toString().replace(".", ""))
	return (Math.r1 / Math.r2) * Math.pow(10, t2 - t1);
}
// 加法
Vue.prototype.accAdd = function(arg1, arg2) {
	var r1, r2, m;
	try {
		r1 = arg1.toString().split(".")[1].length;
	} catch (e) {
		r1 = 0;
	}
	try {
		r2 = arg2.toString().split(".")[1].length;
	} catch (e) {
		r2 = 0;
	}
	m = Math.pow(10, Math.max(r1, r2));
	return (arg1 * m + arg2 * m) / m;
}
// 法
Vue.prototype.subtr = function(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length;
	} catch (e) {
		r1 = 0;
	}
	try {
		r2 = arg2.toString().split(".")[1].length;
	} catch (e) {
		r2 = 0;
	}
	m = Math.pow(10, Math.max(r1, r2));
	//last modify by deeka
	//动态控制精度长度
	n = (r1 >= r2) ? r1 : r2;
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

Vue.prototype.add0 = function(m) {

	return m < 10 ? '0' + m : m
};
Vue.prototype.getDate = function(shijianchuo) {
	//shijianchuo是整数，否则要parseInt转换
	var shijianchuo = parseInt(shijianchuo) * 1000;
	var time = new Date(shijianchuo);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y + '-' + this.add0(m) + '-' + this.add0(d) + ' ' + this.add0(h) + ':' + this.add0(mm) + ':' + this.add0(
		s);
};
//消息时间戳转换
Vue.prototype.getTimestamp = function (date) {
	
	date = date.substring(0,19);
	date = date.replace(/-/g,'/'); //必须把日期'-'转为'/'
	var timestamp = new Date(date).getTime();
	return timestamp;
};

 

Date.prototype.format = function(fmt) { 
     var o = { 
        "M+" : this.getMonth()+1,                 //月份 
        "d+" : this.getDate(),                    //日 
        "h+" : this.getHours(),                   //小时 
        "m+" : this.getMinutes(),                 //分 
        "s+" : this.getSeconds(),                 //秒 
        "q+" : Math.floor((this.getMonth()+3)/3), //季度 
        "S"  : this.getMilliseconds()             //毫秒 
    }; 
    if(/(y+)/.test(fmt)) {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
    }
     for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
         }
     }
    return fmt; 
} 
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
